package com.rp.article.controller;

import com.rp.article.config.RabbitMQDelayConfig;
import com.rp.article.mapper.ArticleMapper;
import com.rp.news.enums.ArticleAppointType;
import com.rp.pojo.Article;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
@Slf4j
public class RabbitMQDelayConsumer {


    @Autowired
    private ArticleMapper articleMapper;

    @RabbitListener(queues = {RabbitMQDelayConfig.QUEUE_DELAY})
    public void consumer(String payload, Message message){
        log.info("--------->{}",payload);

        String receivedRoutingKey = message.getMessageProperties().getReceivedRoutingKey();
        log.info("====>{}", receivedRoutingKey);
        log.info("------->{}",new Date());

        Article article = new Article();
        article.setId(payload);
        article.setIsAppoint(ArticleAppointType.IMMEDIATELY.type);
        articleMapper.updateByPrimaryKeySelective(article);


    }
}
